<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />

		<script type="text/javascript" charset="utf-8">
			function fnGetLinkEntryForItem(id, is_library, entry)
			{
				var ret_str = '';
				if (is_library)
				{
					ret_str = ' < ';
				}
				else
				{
					ret_str = ' > ';
				}

				ret_str = ret_str + '{{<a href="symdb/symbols.txt?callid=' + id + 'calledid=' + entry[1] + '">calls</a>}}';
				return ret_str;
			}

			function fnGetCallGraphStr(callGraphData)
			{
				var num_of_depends = callGraphData.length - 1;

				var is_library = false;
				if (-1 != callGraphData[0][0].indexOf(".so"))
				{
					is_library = true;
				}

				var diag_str = "";
				if (0 == num_of_depends)
				{
					return diag_str;
				}
				if (num_of_depends <= 3)
				{
					diag_str = '() ((' + callGraphData[0][0];

					for (var idx = 0; idx < num_of_depends; idx++)
					{
						diag_str = diag_str + fnGetLinkEntryForItem(callGraphData[0][1], is_library, callGraphData[idx + 1]);
						diag_str += ' [' + 'a'+ idx + ']';
					}
					diag_str += ')) ||';
					for (var idx = 0; idx < num_of_depends; idx++)
					{
						diag_str += ' (' + 'a'+ idx + ':' + callGraphData[idx + 1][0] + ')';
					}
					return diag_str;
				}

				// The first line
				diag_str = ""
				for (var idx = 0; idx < Math.floor(num_of_depends/2); idx++)
				{
					diag_str += '(' + 'a'+ idx + ':' + callGraphData[idx + 1][0] + ') ';
				}

				// The middle line
				diag_str += '||';
				for (var idx = 0; idx < Math.floor(num_of_depends/4); idx++)
				{
					diag_str += ' ()'
				}
				diag_str += ' ((' + callGraphData[0][0];

				// Add all the links
				for (var idx = 0; idx < num_of_depends; idx++)
				{
					diag_str += fnGetLinkEntryForItem(callGraphData[0][1], is_library, callGraphData[idx + 1]);
					diag_str += ' [' + 'a'+ idx + ']';
				}
				diag_str += ')) || ';

				// The last line
				for (var idx = Math.floor(num_of_depends/2); idx < num_of_depends; idx++)
				{
					alert(idx);
					diag_str += '(' + 'a'+ idx + ':' + callGraphData[idx + 1][0] + ') ';
				}
				return diag_str;
			}

			// Test cases
			//var callGraphData = [["nvram",51],["libnvram.so", 2],["libc.so.0", 8],["libcfmapi.so", 3],["libcfmapi.so", 3]];
			//var callGraphData = [["libc.so.0",8],["nvram", 51],["cwmp", 52],["dhcps", 53],["tr111", 54],["ip6tables", 55],["xdslcmd", 56],["sntp", 57],["ipcheck", 58],["wps_monitor", 59],["tc", 60],["dns", 61],["racoon", 62],["bftpd", 63],["log", 64],["equipcmd", 66],["dms", 67],["ethiptunnel", 68],["siproxd", 69],["igmpproxy", 70],["dhcp6c", 72],["smbpasswd", 73],["mic", 74],["upnp", 75],["nas", 76],["rtstat", 77],["scanner", 78],["ppps", 79],["xtmcmd", 80],["wget", 81],["mldproxy", 82],["atserver", 83],["rtacct", 84],["msmtp", 85],["lld2d", 86],["usbmount", 87],["nstat", 88],["ddnsc", 89],["atcmd", 90],["upg", 91],["xsupplicant", 92],["dhcpc", 93],["ripd", 94],["klog", 95],["radvdump", 96],["cms", 97],["udc", 98],["iptables", 99],["ss", 100],["voiper", 101],["ethcmd", 102],["ip", 103],["telnetd", 104],["setkey", 105],["cli", 106],["radvd", 107],["wlancmd", 108],["zebra", 109],["pppoe-server", 110],["dhcp6s", 111],["ifstat", 112],["brctl", 113],["busybox", 114],["pppsd", 115],["ebtables", 116],["smbd", 117],["nmbd", 118],["eapd", 119],["ntfs-3g", 120],["pppc", 121],["web", 122],["sshd", 123],["at", 124],["pppoe", 125],["xl2tpd", 126],["ipp", 127],["mt-daapd", 128]];
			var callGraphData = [["libgplutil.so",10],["bftpd", 63],["siproxd", 69],["dhcp6c", 72],["ppps", 79],["xsupplicant", 92],["radvd", 107],["wlancmd", 108],["dhcp6s", 111],["pppsd", 115],["smbd", 117],["pppc", 121]];
			//var callGraphData = [["nvram",51],["libnvram.so", 2]];
			test_str = fnGetCallGraphStr(callGraphData);
		</script>
		
		<style>
		body {
			font-family: Verdana, Arial, Helvetica, sans-serif;
		}
		</style>
	</head>
	<body>
		<p>Hello, world.</p>
	</body>
</html>
